package Test;

public class test2 {
    public static void main(String[] args) {
int []nums={5,7,7,8,8,10};
        System.out.println(searchRange(nums, 8).toString());
    }


    public static int[] searchRange(int[] nums, int target) {
int left=0,right= nums.length-1,mid=-1;
        int []ret={-1,-1};
        while(left<right){
            mid=left+(right-left)/2;
            if(nums[mid]<target){
                left=mid+1;
            }else {
right=mid;
            }
        }
        if(nums[left]==target){
            ret[0]=left;
        }
        left=0;
        right= nums.length-1;
        while (left<right) {
            mid=left+(right-left)/2;
            if(nums[mid]<=target){
                right=mid-1;
            }else {
                left=mid;
            }
        }
        if(nums[right]==target){
            ret[1]=right;
        }
        return ret;
    }

    public static int search(int[] nums, int target) {
int left=0,right=nums.length-1;
int mid=0;
while(left<=right){
    mid=(left+right)/2;
    if(target>nums[mid]){
        left=mid+1;
    } else if (target<nums[mid]) {
        right=mid-1;
    }else {
        return mid;
    }
}
return -1;
    }


}
